<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <input type="text">
    <button>添加</button>
    <ul class="fruit-list">
        <li>香蕉</li>
        <li>苹果</li>
        <li>鸭梨</li>
    </ul>
    <script>
        let inp = document.querySelector('input');
        let btn = document.querySelector('button');
        let ul = document.querySelector('.fruit-list');
        let lis = document.querySelectorAll('ul>li');
        btn.onclick = function () {
            let value = inp.value;
            let li = document.createElement('li');
            let txt = document.createTextNode(value);
            ul.appendChild(li);
            li.appendChild(txt);
        }
        ul.onclick = function (e) {
            ul.removeChild(e.target);
        }
        
    </script>
</body>

</html>